package com.huawei.appgallery.purchasehistory.ui.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.NetworkRemindBar;
import com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView;
import com.huawei.appgallery.purchasehistory.ui.adapter.FamilyShareAppListAdapter;
import com.huawei.appgallery.purchasehistory.ui.bean.AppInfo;
import com.huawei.appgallery.purchasehistory.ui.bean.QueryFamilySharedAppsResponse;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import huawei.widget.HwSwitch;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.azb;
import o.cfw;
import o.cip;
import o.cja;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cks;
import o.cku;
import o.csp;
import o.cst.d;
import o.cst.h;
import o.ctc;
import o.ctl;
import o.ctu;
import o.ctv;
import o.cvt;
import o.BaseRequest;
import o.Logger;
import o.ContentManager;
import o.CollectCheck;
import o.euf;
import o.evk;

public class FamilyShareEditListFragment<T extends cjo> extends TaskFragment<T> implements OnItemClickListener, com.huawei.appgallery.purchasehistory.ui.adapter.FamilyShareAppListAdapter.a, OnCheckedChangeListener, com.huawei.appgallery.foundation.ui.framework.widget.NetworkRemindBar.c, com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView.a {
    private List<AppInfo> ʹ = new ArrayList();
    private cja ʼ;
    private boolean ʽ = false;
    private NodataWarnLayout ˊ;
    private PullUpListView ˋ;
    private ViewGroup ˎ;
    private FrameLayout ˏ;
    private ViewGroup ॱ;
    private long ॱॱ = 0;
    private FamilyShareAppListAdapter ᐝ;
    private boolean ﹳ = true;
    private HwSwitch ﾞ;
    private boolean ﾟ = false;

    static class a implements OnDismissListener {
        private WeakReference<FamilyShareEditListFragment> ˋ;
        private int ˎ;
        private ctc ˏ;
        private int ॱ;

        a(int i, int i2, ctc o_ctc, FamilyShareEditListFragment familyShareEditListFragment) {
            this.ॱ = i;
            this.ˎ = i2;
            this.ˏ = o_ctc;
            this.ˋ = new WeakReference(familyShareEditListFragment);
        }

        public void onDismiss(DialogInterface dialogInterface) {
            FamilyShareEditListFragment familyShareEditListFragment = null;
            if (this.ˋ != null) {
                familyShareEditListFragment = (FamilyShareEditListFragment) this.ˋ.get();
            }
            if (familyShareEditListFragment != null) {
                if (!familyShareEditListFragment.ﾟ) {
                    if (this.ॱ == 0) {
                        ctu.ˎ(familyShareEditListFragment.ʹ, this.ˎ, this.ˏ);
                    }
                    if (this.ॱ == 1) {
                        familyShareEditListFragment.ˋʻ();
                    } else if (this.ॱ == 0) {
                        familyShareEditListFragment.ˋ(this.ˎ);
                    }
                }
                familyShareEditListFragment.ﾟ = false;
            }
        }
    }

    static class b implements IServerCallBack {
        private int ˋ;
        private ctc ˎ;
        private WeakReference<FamilyShareEditListFragment> ˏ;
        private int ॱ;

        b(int i, int i2, ctc o_ctc, FamilyShareEditListFragment familyShareEditListFragment) {
            this.ˋ = i;
            this.ॱ = i2;
            this.ˎ = o_ctc;
            this.ˏ = new WeakReference(familyShareEditListFragment);
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            FamilyShareEditListFragment familyShareEditListFragment = null;
            if (this.ˏ != null) {
                familyShareEditListFragment = (FamilyShareEditListFragment) this.ˏ.get();
            }
            if (familyShareEditListFragment == null) {
                return;
            }
            if (ctv.ॱ(responseBean.getResponseCode(), responseBean.getRtnCode_())) {
                csp.ˏ.ˋ("FamilyShareEditListFragment", "success  familyShare = " + this.ˎ.ॱ() + " allShared = " + this.ˎ.ˋ() + " pgk = " + this.ˎ.ˏ());
                ctu.ˊ(familyShareEditListFragment.ʹ, this.ˋ, this.ॱ, this.ˎ);
                if (this.ˋ == 0) {
                    familyShareEditListFragment.ˋ(this.ॱ);
                    familyShareEditListFragment.ˋʻ();
                    return;
                }
                familyShareEditListFragment.ᐝ.notifyDataSetChanged();
                familyShareEditListFragment.ˋʻ();
                return;
            }
            csp.ˏ.ˋ("FamilyShareEditListFragment", "failed   familyShare = " + this.ˎ.ॱ() + " allShared = " + this.ˎ.ˋ() + " pgk = " + this.ˎ.ˏ() + " rtnCode = " + responseBean.getRtnCode_() + " responseCode = " + responseBean.getResponseCode());
            evk.ॱ(ContentManager.getInstant().getContext().getString(h.ˊॱ), 0).ˋ();
            if (this.ˋ == 0) {
                familyShareEditListFragment.ˋ(this.ॱ);
            } else {
                familyShareEditListFragment.ˋʻ();
            }
        }
    }

    static class c implements cks {
        private int ˋ;
        private WeakReference<FamilyShareEditListFragment> ˎ;
        private ctc ˏ;
        private int ॱ;

        c(int i, int i2, ctc o_ctc, FamilyShareEditListFragment familyShareEditListFragment) {
            this.ˋ = i;
            this.ॱ = i2;
            this.ˏ = o_ctc;
            this.ˎ = new WeakReference(familyShareEditListFragment);
        }

        public void enableNetworking() {
            FamilyShareEditListFragment familyShareEditListFragment = null;
            if (this.ˎ != null) {
                familyShareEditListFragment = (FamilyShareEditListFragment) this.ˎ.get();
            }
            if (familyShareEditListFragment != null) {
                familyShareEditListFragment.ˋʼ();
                familyShareEditListFragment.ﾟ = true;
                if (this.ˋ == 0) {
                    ctu.ˎ(familyShareEditListFragment.ʹ, this.ॱ, this.ˏ);
                }
                familyShareEditListFragment.ॱ(this.ˋ, this.ॱ, this.ˏ);
            }
        }

        public void upgrade() {
        }

        public void ˋ() {
        }
    }

    public boolean ˊ(TaskFragment taskFragment, com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        ResponseBean responseBean = bVar.ˋ;
        this.ॱॱ = System.currentTimeMillis();
        if (ctv.ॱ(responseBean.getResponseCode(), responseBean.getRtnCode_())) {
            this.ʽ = false;
            ॱˋ(true);
            ʼ(0);
            ॱ(bVar);
            ʽˊ();
            return super.ˊ(taskFragment, bVar);
        }
        ॱ(responseBean.getResponseType(), responseBean);
        this.ʽ = true;
        return super.ˊ(taskFragment, bVar);
    }

    public void ˏ(Bundle bundle) {
        super.ˏ(bundle);
        this.ʽ = false;
    }

    @Nullable
    public View ˋ(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
        this.ˎ = (ViewGroup) layoutInflater.inflate(ˋʽ(), viewGroup, false);
        ˏ(this.ˎ);
        if (ʼʻ()) {
            ʽˊ();
        } else {
            ˏ(layoutInflater);
            if (this.ʽ) {
                ﾟॱ();
            }
        }
        return this.ˎ;
    }

    private void ˏ(ViewGroup viewGroup) {
        if (viewGroup != null) {
            if (this.ʼ == null) {
                this.ʼ = new cip();
            }
            View view = (NetworkRemindBar) viewGroup.findViewById(e.ˎˎ);
            if (view != null) {
                azb.ˏ(view);
                view.setNetworkRemindBarListener(this);
            }
            this.ˊ = (NodataWarnLayout) viewGroup.findViewById(e.ˑ);
            if (this.ˊ != null) {
                azb.ˏ(this.ˊ);
                ˏ(this.ˊ);
            }
            this.ˏ = (FrameLayout) viewGroup.findViewById(e.ˍ);
            azb.ˏ(this.ˏ);
            this.ॱ = ॱ();
            if (this.ॱ != null) {
                azb.ˏ(this.ॱ);
            }
            this.ˋ = (PullUpListView) viewGroup.findViewById(e.ॱˊ);
            ˌॱ();
            ʾॱ();
        }
    }

    private ViewGroup ॱ() {
        if (this.ˎ != null) {
            this.ॱ = (ViewGroup) this.ˎ.findViewById(e.ˌ);
            this.ﾞ = (HwSwitch) this.ˎ.findViewById(e.ˉ);
            this.ﾞ.setOnCheckedChangeListener(this);
        }
        return this.ॱ;
    }

    public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
        if (compoundButton.getId() == e.ˉ) {
            int i;
            ctc o_ctc = new ctc();
            if (this.ﾞ.isChecked()) {
                i = 1;
            } else {
                i = 0;
            }
            o_ctc.ॱ(i);
            o_ctc.ˎ(ctu.ˏ(this.ʹ));
            ॱ(1, 0, o_ctc);
        }
    }

    private void ॱ(com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        Collection ॱ = ((QueryFamilySharedAppsResponse) bVar.ˋ).ॱ();
        if (this.ʹ != null && ॱ != null) {
            this.ʹ.clear();
            this.ʹ.addAll(ॱ);
        }
    }

    private void ʽˊ() {
        if (CollectCheck.isEmpty(this.ʹ)) {
            ˋॱ(false);
            return;
        }
        ˋॱ(true);
        ˋʻ();
        ˉॱ();
    }

    private void ʾॱ() {
        if (this.ˋ != null) {
            this.ᐝ = new FamilyShareAppListAdapter(ॱˊ(), this.ʹ);
            this.ˋ.setAdapter(this.ᐝ);
            this.ᐝ.setOnItemCheckedChangeListener(this);
        }
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        list.add(ctl.ʻ());
    }

    private void ˉॱ() {
        if (this.ᐝ == null) {
            this.ᐝ = new FamilyShareAppListAdapter(ॱˊ(), this.ʹ);
        }
        this.ᐝ.notifyDataSetChanged();
    }

    public void ˌ() {
        super.ˌ();
        if (this.ॱॱ > 0 && System.currentTimeMillis() - this.ॱॱ > 2000) {
            this.ॱॱ = System.currentTimeMillis();
            if (!ʼʻ() && this.ʼ != null && this.ʼ.ˎ()) {
                Logger.ˎ("FamilyShareEditListFragment", "onResume again , will retryConnect()");
                ﾟॱ();
            }
        }
    }

    public void ᐝ() {
        this.ॱॱ = 0;
        ʼ(0);
        if (this.ˏ != null) {
            this.ˏ.removeAllViews();
            this.ˏ = null;
        }
        this.ˎ = null;
        this.ˋ = null;
        super.ᐝ();
    }

    private void ॱ(com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.a aVar, ResponseBean responseBean) {
        if (aVar != com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.a.UPDATE_CACHE) {
            ˊʻ();
            if (this.ʼ != null) {
                this.ʼ.onEvent(ctv.ˏ(responseBean));
            }
        }
    }

    private void ˊʻ() {
        ˋ(this.ˋ, 4);
        ˋ(this.ˊ, 8);
        if (this.ॱ != null) {
            ˋ(this.ॱ, 8);
        }
    }

    private void ˋॱ(boolean z) {
        View view;
        int i;
        int i2 = 8;
        if (this.ॱ != null) {
            view = this.ॱ;
            if (z) {
                i = 0;
            } else {
                i = 8;
            }
            ˋ(view, i);
        }
        view = this.ˋ;
        if (z) {
            i = 0;
        } else {
            i = 8;
        }
        ˋ(view, i);
        View view2 = this.ˊ;
        if (!z) {
            i2 = 0;
        }
        ˋ(view2, i2);
    }

    private int ˋʽ() {
        return d.ʼ;
    }

    private void ˏ(NodataWarnLayout nodataWarnLayout) {
        if (nodataWarnLayout != null) {
            nodataWarnLayout.setWarnImage(o.dky.a.ˊˊ);
            nodataWarnLayout.setWarnTextOne(h.ʽ);
            nodataWarnLayout.setWarnTextTwo(h.ᐝ);
            nodataWarnLayout.setViewVisible(NodataWarnLayout.e.WARN_BTN, 8);
        }
    }

    private void ˌॱ() {
        if (this.ˋ != null) {
            this.ˋ.setLoadingListener(this);
            this.ˋ.setVerticalScrollBarEnabled(false);
            this.ˋ.setDrawSelectorOnTop(false);
            this.ˋ.setSelector(new ColorDrawable(0));
            this.ˋ.setOnItemClickListener(this);
        }
    }

    public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
        AppInfo appInfo = (AppInfo) this.ʹ.get(i);
        ˊ(appInfo.ॱॱ(), appInfo.ᐝ());
    }

    public void b_(int i) {
        int i2;
        ctc o_ctc = new ctc();
        AppInfo appInfo = (AppInfo) this.ʹ.get(i);
        o_ctc.ˎ(appInfo.ˏ());
        if (appInfo.ˋ() == 0) {
            i2 = 1;
        } else {
            i2 = 0;
        }
        o_ctc.ˋ(i2);
        ॱ(0, i, o_ctc);
    }

    private void ˊ(String str, String str2) {
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        appDetailActivityProtocol.ˏ(new Request(str, str2));
        cjk.ˎ().ˋ(ॱˋ(), new cjm("appdetail.activity", appDetailActivityProtocol));
    }

    private void ˊ(int i, int i2, ctc o_ctc) {
        Context ॱˊ = ॱˊ();
        if (ॱˊ instanceof Activity) {
            Context context = (Activity) ॱˊ;
            cku ˋ = cku.ˋ(null, ॱˊ.getResources().getString(h.ॱॱ));
            ˋ.ॱ(new c(i, i2, o_ctc, this));
            ˋ.ˎ(new a(i, i2, o_ctc, this));
            ˋ.ˎ(context);
        }
    }

    private void ˋʻ() {
        this.ﾞ.setOnCheckedChangeListener(null);
        if (ctu.ॱ(this.ʹ)) {
            this.ﾞ.setChecked(true);
        } else {
            this.ﾞ.setChecked(false);
        }
        this.ﾞ.setOnCheckedChangeListener(this);
    }

    private void ॱ(int i, int i2, ctc o_ctc) {
        if (o_ctc != null) {
            if ((o_ctc.ॱ() == 1 || o_ctc.ˋ() == 1) && ˊʽ()) {
                ˊ(i, i2, o_ctc);
                if (i == 0) {
                    ctu.ˏ(this.ʹ, i2, o_ctc);
                    return;
                }
                return;
            }
            cfw.ˎ(o_ctc, new b(i, i2, o_ctc, this));
        }
    }

    private boolean ˊʽ() {
        if (this.ﹳ) {
            this.ﹳ = euf.ˎ().ˏ("first_share_family", true);
        }
        return this.ﹳ;
    }

    private void ˋʼ() {
        euf.ˎ().ˋ("first_share_family", false);
        this.ﹳ = false;
    }

    private void ˋ(int i) {
        if (this.ᐝ != null && this.ˋ != null) {
            this.ᐝ.updateItemView(this.ˋ, i);
        }
    }

    private void ˏ(LayoutInflater layoutInflater) {
        if (this.ʼ != null && this.ʼ.ˎ()) {
            this.ʼ.onEvent(0);
            this.ʼ = null;
            ˋ(this.ˏ, 8);
        }
        if (this.ʼ == null || this.ˏ == null) {
            Logger.e("FamilyShareEditListFragment", "showLoading, loadingCtl = " + this.ʼ + ", loadingContainer = " + this.ˏ);
            return;
        }
        View ˏ = this.ʼ.ˏ(layoutInflater);
        this.ʼ.ˊ();
        ˋ(this.ˏ, 0);
        this.ˏ.removeAllViews();
        this.ˏ.addView(ˏ);
        this.ʼ.ˋ(new OnClickListener(this) {
            final /* synthetic */ FamilyShareEditListFragment ˎ;

            {
                this.ˎ = r1;
            }

            public void onClick(View view) {
                this.ˎ.ʼᐝ();
                Logger.ˎ("FamilyShareEditListFragment", "loadingCtl onClick will onLoadingRetry()");
            }
        });
        this.ʼ.ˏ();
    }

    private void ʼ(int i) {
        if (this.ʼ != null && this.ʼ.ˎ()) {
            this.ʼ.onEvent(i);
            this.ʼ = null;
        }
        ˋ(this.ˏ, 8);
    }

    private void ˋ(View view, int i) {
        if (view != null && view.getVisibility() != i) {
            view.setVisibility(i);
        }
    }

    public void ﾟॱ() {
        if (this.ʼ instanceof cip) {
            ((cip) this.ʼ).ˊ();
        }
        ʼᐝ();
    }

    public void ﹶ() {
    }

    public void ʳ() {
    }

    public void ʽᐝ() {
    }

    public void ʼᐝ() {
        ʿˊ();
    }

    public void ˈॱ() {
    }

    public void ˊʼ() {
    }

    public void ʿॱ() {
    }
}
